package com.songshuai.webapi.baseapi.pojo;

import com.songshuai.webapi.baseapi.enumerations.ResultStatus;
import lombok.Data;
import lombok.ToString;


@Data
@ToString
public class QueryResponse<T> {

    /**
     * 返回码
     */
    private Integer code;

    /**
     * 返回信息描述
     */
    private String message;


    /**
     * 返回数据
     */
    private T data;

    public QueryResponse() {
        code = ResultStatus.SUCCESS.getErrorCode();
        message = ResultStatus.SUCCESS.getErrorMsg();
    }

    public QueryResponse(ResultStatus resultStatus) {
        code = resultStatus.getErrorCode();
        message = resultStatus.getErrorMsg();
    }

    public QueryResponse(int code,String message) {
        this.code = code;
        this.message = message;
    }

    public static <T> QueryResponse setResData(T data) {
        QueryResponse<T> res = new QueryResponse<>();
        res.setData(data);
        return res;
    }


    public static <T> QueryResponse setResData(T data, ResultStatus resultStatus) {
        QueryResponse<T> res = new QueryResponse<>();
        res.setData(data);
        res.setCode(resultStatus.getErrorCode());
        res.setMessage(resultStatus.getErrorMsg());
        return res;
    }

    public static <T> QueryResponse setResData(T data, ResultStatus resultStatus, String msg) {
        QueryResponse<T> res = new QueryResponse<>();
        res.setData(data);
        res.setCode(resultStatus.getErrorCode());
        res.setMessage(msg);
        return res;
    }

    public static <T> QueryResponse setResData(T data, Integer errCode, String msg) {
        QueryResponse<T> res = new QueryResponse<>();
        res.setData(data);
        res.setCode(errCode);
        res.setMessage(msg);
        return res;
    }


}
